<?php
class cast_language extends Model{
	public static function getTableName(){
		return 'cast-language';
	}
	public function getPrimaryKey(){
		return array('cast_id','language_id');
	}

	public function set($object){
		$this->language_id = !isset($object->language_id) ? '0' : $object->language_id;
		$this->real_first_name = !isset($object->real_first_name) ? '' : trim($object->real_first_name);
		$this->real_last_name = !isset($object->real_last_name) ? '' : trim($object->real_last_name);
		$this->first_name = !isset($object->first_name) ? '' : trim($object->first_name);
		$this->last_name = !isset($object->last_name) ? '' : trim($object->last_name);
		$this->other_name = !isset($object->other_name) ? '' : trim($object->other_name);
		$this->nickname = !isset($object->nickname) ? '' : trim($object->nickname);
		$this->occupation = !isset($object->occupation) ? '' : trim($object->occupation);
		$this->personality = !isset($object->personality) ? '' : $object->personality;
		$this->profile = !isset($object->profile) ? '' : $object->profile;
		$this->history = !isset($object->history) ? '' : $object->history;
	}

	public function getLangCastByID($cast_id, $lan_id)
	{
		$sql = "select * from `".self::getTableName()."` where cast_id='{$cast_id}' and language_id='{$lan_id}'";
		$ret = Model::$dbo["r"]->findBySql(__class__, $sql); 
		return isset($ret[0]) ? $ret[0] : false;
	}

	public function delBySql($cast_id)
	{
		$sql = "delete from `".self::getTableName()."` where cast_id='{$cast_id}'";
		return Model::$dbo["w"]->getDbHandle()->exec($sql);
	}

	public function getCastByID($cast_id)
	{
		$sql = "select * from `".self::getTableName()."` where cast_id='{$cast_id}'";
		$ret = Model::$dbo['r']->findBySql(__class__, $sql);
		return empty($ret) ? false : $ret[0];
	}

	/*
	 * by donald
	 */
	public function getAll($cast_id)
	{
		return self::$dbo['w']->find(__CLASS__, 'cast_id = ?', array($cast_id));
	}
}
?>
